package com.zprmb.udzt.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TimeUtils {
	public static final String HOUR_FORMAT = "HH:mm";
	public static final String YEAR_FORMAT = "yyyy-MM-dd";

	public static String milsToDate() {
		Date date = new Date(System.currentTimeMillis());
		SimpleDateFormat format = new SimpleDateFormat("MM-dd hh:mm");
		String time = format.format(date);
		return time;
	}

	public static int getDateSx() {
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(System.currentTimeMillis());
		int hour = cal.get(Calendar.HOUR_OF_DAY);
		int val=0;
		if (hour >= 6 && hour < 8) {
			val=0;
		} else if (hour >= 8 && hour < 11) {
			val=0;
		} else if (hour >= 11 && hour < 13) {
			val=1;
		} else if (hour >= 13 && hour < 18) {
			val= 2;
		} else {
			val= 3;
		}
		return val;
	}

	public static String commonDateTimeFormat(Date date) {
		SimpleDateFormat format = new SimpleDateFormat(HOUR_FORMAT);
		String str = format.format(date);
		return str;
	}

	public static Date commonDateTimeParse(String dateStr) {
		SimpleDateFormat format = new SimpleDateFormat(HOUR_FORMAT);
		try {
			Date date = format.parse(dateStr);
			return date;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static String formatYear(Date date) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(YEAR_FORMAT);
		String format = dateFormat.format(date);
		return format;
	}
	/**
	 * 获取最详细的时间
	 * @param date
	 * @return
	 */
	public static String formatAllTime(Date date) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String format = dateFormat.format(date);
		return format;
	}
	
	/**
	 * 获取年月日
	 * @return
	 */
	public static String formatTime(Date date) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String format = dateFormat.format(date);
		return format;
	}
	
	public static String getNowTime() {
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		String str = dateFormat.format(now);
		//Calendar calendar = Calendar.getInstance();
		return str;
	}

	public static String getUpMothDate() {
		String str = "";
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		Calendar lastDate = Calendar.getInstance();
		lastDate.add(Calendar.MONTH, -1);// ��һ����
		str = sdf.format(lastDate.getTime());
		return str;
	}

}
